package com.wn.controller;

import com.wn.bean.Stu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yellow Docter
 * @date 2022 -07-14
 * @desc
 */
@RestController
public class IndexController {

    @Value("${name}")
    private String name;
    @Value("${age}")
    private Integer age;

    @Value("${favs[1]}")
    private String favs;

    @Value("${stu.name}")
    private String stuName;

    @Value("${stu.age}")
    private String stuAge;

    @RequestMapping("/demo01")
    public String demo01(){
        System.out.println("name = " + name);
        System.out.println("age = " + age);
        System.out.println("favs = " + favs);
        System.out.println("stuName = " + stuName);
        System.out.println("stuAge = " + stuAge);

        return "demo01";
    }

    @Autowired
    private Environment environment;

    /**
     *environment 可以获取数据
     *  environment.getProperty("name"); 获取数据
     * @return
     */
    @RequestMapping("/demo02")
    public String demo02(){

        String name = environment.getProperty("name");
        String age = environment.getProperty("age");
        String favs = environment.getProperty("favs[2]");

        String stuName = environment.getProperty("stu.name");
        String stuAge = environment.getProperty("stu.age");

        System.out.println("favs = " + favs);
        System.out.println("name = " + name);
        System.out.println("age = " + age);


        System.out.println("stuName = " + stuName);
        System.out.println("stuAge = " + stuAge);

        return "demo02";
    }

    @Autowired
    private Stu stu;

    @RequestMapping("/demo03")
    public String demo03(){

        System.out.println("stu = " + stu);

        return "demo03";
    }
}

